@editora/plugins 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +57 -4
  2. package/dist/_commonjsHelpers-BH3jXuIh.js +1 -0
  3. package/dist/_commonjsHelpers-ByX85dGu.mjs +33 -0
  4. package/dist/anchor.cjs.js +11 -11
  5. package/dist/anchor.esm.js +130 -107
  6. package/dist/anchoredPopover-BzqGPOAE.js +1 -0
  7. package/dist/anchoredPopover-Dts0IrgU.mjs +106 -0
  8. package/dist/background-color.cjs.js +3 -3
  9. package/dist/background-color.esm.js +116 -119
  10. package/dist/code.cjs.js +82 -102
  11. package/dist/code.esm.js +1172 -662
  12. package/dist/comments.cjs.js +10 -10
  13. package/dist/comments.esm.js +195 -177
  14. package/dist/document-manager.cjs.js +1 -1
  15. package/dist/document-manager.esm.js +1 -1
  16. package/dist/documentManager-CTqRftU8.mjs +8369 -0
  17. package/dist/documentManager-Jf0RbSks.js +17 -0
  18. package/dist/embed-iframe.cjs.js +2 -2
  19. package/dist/embed-iframe.esm.js +8 -5
  20. package/dist/emojis.cjs.js +64 -39
  21. package/dist/emojis.esm.js +133 -104
  22. package/dist/html2canvas.esm-B5qzocYs.js +5 -0
  23. package/dist/html2canvas.esm-BWVIUcAF.mjs +4802 -0
  24. package/dist/{index-Bskk414V.mjs → index-BFsKNTTj.mjs} +50 -50
  25. package/dist/index-CvJk4DKa.js +221 -0
  26. package/dist/index-D3CycEFU.mjs +16543 -0
  27. package/dist/index-tqLTHcO6.js +1 -0
  28. package/dist/index.cjs.js +1 -1
  29. package/dist/{index.es-Cz1qItab.js → index.es-CE_A4QSm.js} +5 -5
  30. package/dist/{index.es-DEcRmSTY.mjs → index.es-DQ78mYYo.mjs} +4 -3
  31. package/dist/index.esm.js +87 -79
  32. package/dist/jspdf.es.min-BoS80556.js +77 -0
  33. package/dist/jspdf.es.min-DQCoX5yh.mjs +7889 -0
  34. package/dist/link.cjs.js +6 -6
  35. package/dist/link.esm.js +41 -39
  36. package/dist/math.cjs.js +21 -21
  37. package/dist/math.esm.js +151 -112
  38. package/dist/media-manager.cjs.js +15 -15
  39. package/dist/media-manager.esm.js +227 -206
  40. package/dist/merge-tag.cjs.js +44 -12
  41. package/dist/merge-tag.esm.js +368 -241
  42. package/dist/page-break.cjs.js +2 -2
  43. package/dist/page-break.esm.js +77 -69
  44. package/dist/special-characters.cjs.js +83 -45
  45. package/dist/special-characters.esm.js +149 -100
  46. package/dist/spell-check.cjs.js +9 -9
  47. package/dist/spell-check.esm.js +235 -216
  48. package/dist/template.cjs.js +14 -14
  49. package/dist/template.esm.js +157 -131
  50. package/dist/text-color.cjs.js +9 -9
  51. package/dist/text-color.esm.js +131 -115
  52. package/index.d.ts +51 -1
  53. package/package.json +6 -4
  54. package/dist/colorSelectionApply-C0iOfMWb.js +0 -1
  55. package/dist/colorSelectionApply-D8r_gV32.mjs +0 -63
  56. package/dist/documentManager-DRUc1-Cs.mjs +0 -37581
  57. package/dist/documentManager-_tQQfQi9.js +0 -317
  58. package/dist/index-D3pJyAsj.js +0 -1
package/README.md CHANGED
@@ -17,6 +17,12 @@ Comprehensive plugin collection for Editora Rich Text Editor with 40+ plugins fo
17
17
  npm install @editora/plugins @editora/core @editora/themes
18
18
  ```
19
19
 
20
+ When using plugin UI features (table toolbar, pickers, dialogs), also import:
21
+
22
+ ```ts
23
+ import "@editora/plugins/styles.css";
24
+ ```
25
+
20
26
  ## 🎯 Overview
21
27
 
22
28
  This package provides a complete set of plugins for building feature-rich text editors. Each plugin is modular, tree-shakeable, and can be used independently.
@@ -109,6 +115,7 @@ import {
109
115
  StrikethroughPlugin
110
116
  } from '@editora/plugins';
111
117
 
118
+ import "@editora/plugins/styles.css";
112
119
  import "@editora/themes/themes/default.css";
113
120
  const plugins = [
114
121
  BoldPlugin(),
@@ -588,15 +595,61 @@ const collaborativePlugins = [
588
595
  }),
589
596
  MergeTagPlugin({
590
597
  tags: [
591
- { label: 'First Name', value: '{{firstName}}' },
592
- { label: 'Last Name', value: '{{lastName}}' },
593
- { label: 'Email', value: '{{email}}' }
594
- ]
598
+ { label: 'First Name', value: '{{firstName}}', category: 'User' },
599
+ { label: 'Last Name', value: '{{lastName}}', category: 'User' },
600
+ { label: 'Email', value: '{{email}}', category: 'User' }
601
+ ],
602
+ defaultCategory: 'User',
603
+ dialog: {
604
+ title: 'Insert Variable',
605
+ searchPlaceholder: 'Search variables...',
606
+ showPreview: true
607
+ },
608
+ tokenTemplate: '{value}'
595
609
  }),
596
610
  HistoryPlugin()
597
611
  ];
598
612
  ```
599
613
 
614
+ `MergeTagPlugin` supports functional customization:
615
+
616
+ - `tags`: flat list of tags (auto-grouped by `category`)
617
+ - `categories`: explicit grouped categories with custom order
618
+ - `defaultCategory`: initial tab
619
+ - `dialog`: labels/placeholders/preview toggle
620
+ - `tokenTemplate`: string template (`{key}`, `{label}`, `{category}`, `{value}`) or formatter function
621
+
622
+ ### Custom Templates
623
+
624
+ You can register your own templates before initializing the editor:
625
+
626
+ ```typescript
627
+ import { TemplatePlugin, addCustomTemplate } from '@editora/plugins';
628
+
629
+ addCustomTemplate({
630
+ id: 'invoice-basic',
631
+ name: 'Invoice (Basic)',
632
+ category: 'Billing',
633
+ description: 'Simple invoice template',
634
+ html: `
635
+ <h1>Invoice</h1>
636
+ <p><strong>Customer:</strong> {{customer.name}}</p>
637
+ <p><strong>Date:</strong> {{today}}</p>
638
+ <p><strong>Total:</strong> {{invoice.total}}</p>
639
+ `,
640
+ tags: ['invoice', 'billing']
641
+ });
642
+
643
+ const plugins = [
644
+ TemplatePlugin()
645
+ ];
646
+ ```
647
+
648
+ Notes:
649
+ - `id` must be unique.
650
+ - HTML is sanitized on insertion.
651
+ - Use `validateTemplate(template)` if you want to pre-check templates before registering.
652
+
600
653
  ## 🔧 TypeScript Support
601
654
 
602
655
  All plugins include full TypeScript definitions:
@@ -0,0 +1 @@
1
+ "use strict";var u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function f(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var n=e.default;if(typeof n=="function"){var t=function o(){var r=!1;try{r=this instanceof o}catch{}return r?Reflect.construct(n,arguments,this.constructor):n.apply(this,arguments)};t.prototype=n.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}),t}exports.commonjsGlobal=u;exports.getAugmentedNamespace=l;exports.getDefaultExportFromCjs=f;
@@ -0,0 +1,33 @@
1
+ var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
+ function a(e) {
3
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
+ }
5
+ function f(e) {
6
+ if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
7
+ var n = e.default;
8
+ if (typeof n == "function") {
9
+ var t = function r() {
10
+ var o = !1;
11
+ try {
12
+ o = this instanceof r;
13
+ } catch {
14
+ }
15
+ return o ? Reflect.construct(n, arguments, this.constructor) : n.apply(this, arguments);
16
+ };
17
+ t.prototype = n.prototype;
18
+ } else t = {};
19
+ return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
20
+ var o = Object.getOwnPropertyDescriptor(e, r);
21
+ Object.defineProperty(t, r, o.get ? o : {
22
+ enumerable: !0,
23
+ get: function() {
24
+ return e[r];
25
+ }
26
+ });
27
+ }), t;
28
+ }
29
+ export {
30
+ f as a,
31
+ u as c,
32
+ a as g
33
+ };
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("./editorContainerHelpers-CFbfiOJI.js"),h=new Set,m='[data-theme="dark"], .dark, .editora-theme-dark';function z(){if(typeof window>"u"||window.__anchorObserverInitialized)return;window.__anchorObserverInitialized=!0,new MutationObserver(d=>{d.forEach(s=>{s.removedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const l=r;if(l.classList?.contains("rte-anchor")){const a=l.id;a&&h.delete(a)}l.querySelectorAll?.(".rte-anchor")?.forEach(a=>{const u=a.id;u&&h.delete(u)})}})})}).observe(document.body,{childList:!0,subtree:!0})}function S(o){return!o||o.trim().length===0?{valid:!1,error:"Anchor ID cannot be empty"}:o.length>256?{valid:!1,error:"Anchor ID must be less than 256 characters"}:/^[a-z_]/.test(o)?/^[a-z0-9\-_]+$/.test(o)?{valid:!0,error:""}:{valid:!1,error:"Anchor ID can only contain letters, numbers, hyphens, and underscores"}:{valid:!1,error:"Anchor ID must start with a letter or underscore"}}function R(){const o=w.findEditorContainerFromSelection();if(!o)return;const d=w.getContentElement(o);if(!d)return;const s=d.querySelectorAll(".rte-anchor"),r=new Set;s.forEach(l=>{const e=l.id;e&&r.add(e)}),h.clear(),r.forEach(l=>h.add(l))}function N(o){if(o){const r=o.startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(m))return!0}const d=window.getSelection();if(d&&d.rangeCount>0){const r=d.getRangeAt(0).startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(m))return!0}return document.activeElement?.closest(m)?!0:document.body.matches(m)||document.documentElement.matches(m)}function M(o,d,s,r){R();const l=N(r),e=l?{overlay:"rgba(0, 0, 0, 0.62)",dialogBg:"#1f2937",panelBg:"#222d3a",border:"#3b4657",text:"#e2e8f0",muted:"#94a3b8",closeHoverBg:"#334155",fieldBg:"#111827",fieldFocusBg:"#111827",fieldBorder:"#4b5563",fieldText:"#e2e8f0",fieldErrorBg:"#3f2124",fieldErrorBorder:"#ef4444",cancelBg:"#334155",cancelHover:"#475569",cancelText:"#e2e8f0",saveBg:"#3b82f6",saveHover:"#2563eb",saveDisabledBg:"#374151",saveDisabledText:"#7f8ca1",help:"#9fb0c6",focusRing:"rgba(88, 166, 255, 0.25)",errorRing:"rgba(239, 68, 68, 0.25)"}:{overlay:"rgba(0, 0, 0, 0.5)",dialogBg:"#ffffff",panelBg:"#f9f9f9",border:"#e0e0e0",text:"#333333",muted:"#999999",closeHoverBg:"#e0e0e0",fieldBg:"#ffffff",fieldFocusBg:"#f9f9ff",fieldBorder:"#d0d0d0",fieldText:"#333333",fieldErrorBg:"#ffebee",fieldErrorBorder:"#d32f2f",cancelBg:"#f0f0f0",cancelHover:"#e0e0e0",cancelText:"#333333",saveBg:"#0066cc",saveHover:"#0052a3",saveDisabledBg:"#d0d0d0",saveDisabledText:"#999999",help:"#999999",focusRing:"rgba(0, 102, 204, 0.1)",errorRing:"rgba(211, 47, 47, 0.1)"},a=document.createElement("div");a.className="rte-anchor-dialog-overlay",a.style.cssText=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("./editorContainerHelpers-CFbfiOJI.js"),b=new Set,x='[data-theme="dark"], .dark, .editora-theme-dark';function $(t,c){if(c===t.innerHTML)return;const i=window.execEditorCommand||window.executeEditorCommand;if(typeof i=="function")try{i("recordDomTransaction",t,c,t.innerHTML)}catch{}}function z(){if(typeof window>"u"||window.__anchorObserverInitialized)return;window.__anchorObserverInitialized=!0,new MutationObserver(c=>{c.forEach(i=>{i.removedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const d=r;if(d.classList?.contains("rte-anchor")){const n=d.id;n&&b.delete(n)}d.querySelectorAll?.(".rte-anchor")?.forEach(n=>{const u=n.id;u&&b.delete(u)})}})})}).observe(document.body,{childList:!0,subtree:!0})}function S(t){return!t||t.trim().length===0?{valid:!1,error:"Anchor ID cannot be empty"}:t.length>256?{valid:!1,error:"Anchor ID must be less than 256 characters"}:/^[a-z_]/.test(t)?/^[a-z0-9\-_]+$/.test(t)?{valid:!0,error:""}:{valid:!1,error:"Anchor ID can only contain letters, numbers, hyphens, and underscores"}:{valid:!1,error:"Anchor ID must start with a letter or underscore"}}function M(){const t=w.findEditorContainerFromSelection();if(!t)return;const c=w.getContentElement(t);if(!c)return;const i=c.querySelectorAll(".rte-anchor"),r=new Set;i.forEach(d=>{const e=d.id;e&&r.add(e)}),b.clear(),r.forEach(d=>b.add(d))}function R(t){if(t){const r=t.startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(x))return!0}const c=window.getSelection();if(c&&c.rangeCount>0){const r=c.getRangeAt(0).startContainer;if((r.nodeType===Node.ELEMENT_NODE?r:r.parentElement)?.closest(x))return!0}return document.activeElement?.closest(x)?!0:document.body.matches(x)||document.documentElement.matches(x)}function H(t,c,i,r){M();const d=R(r),e=d?{overlay:"rgba(0, 0, 0, 0.62)",dialogBg:"#1f2937",panelBg:"#222d3a",border:"#3b4657",text:"#e2e8f0",muted:"#94a3b8",closeHoverBg:"#334155",fieldBg:"#111827",fieldFocusBg:"#111827",fieldBorder:"#4b5563",fieldText:"#e2e8f0",fieldErrorBg:"#3f2124",fieldErrorBorder:"#ef4444",cancelBg:"#334155",cancelHover:"#475569",cancelText:"#e2e8f0",saveBg:"#3b82f6",saveHover:"#2563eb",saveDisabledBg:"#374151",saveDisabledText:"#7f8ca1",help:"#9fb0c6",focusRing:"rgba(88, 166, 255, 0.25)",errorRing:"rgba(239, 68, 68, 0.25)"}:{overlay:"rgba(0, 0, 0, 0.5)",dialogBg:"#ffffff",panelBg:"#f9f9f9",border:"#e0e0e0",text:"#333333",muted:"#999999",closeHoverBg:"#e0e0e0",fieldBg:"#ffffff",fieldFocusBg:"#f9f9ff",fieldBorder:"#d0d0d0",fieldText:"#333333",fieldErrorBg:"#ffebee",fieldErrorBorder:"#d32f2f",cancelBg:"#f0f0f0",cancelHover:"#e0e0e0",cancelText:"#333333",saveBg:"#0066cc",saveHover:"#0052a3",saveDisabledBg:"#d0d0d0",saveDisabledText:"#999999",help:"#999999",focusRing:"rgba(0, 102, 204, 0.1)",errorRing:"rgba(211, 47, 47, 0.1)"},n=document.createElement("div");n.className="rte-anchor-dialog-overlay",n.style.cssText=`
2
2
  position: fixed;
3
3
  top: 0;
4
4
  left: 0;
@@ -19,7 +19,7 @@
19
19
  max-width: 450px;
20
20
  overflow: hidden;
21
21
  animation: rte-anchor-dialog-appear 0.2s ease;
22
- `,!document.getElementById("rte-anchor-dialog-styles")){const i=document.createElement("style");i.id="rte-anchor-dialog-styles",i.textContent=`
22
+ `,!document.getElementById("rte-anchor-dialog-styles")){const s=document.createElement("style");s.id="rte-anchor-dialog-styles",s.textContent=`
23
23
  @keyframes rte-anchor-dialog-appear {
24
24
  from { opacity: 0; transform: scale(0.95); }
25
25
  to { opacity: 1; transform: scale(1); }
@@ -27,14 +27,14 @@
27
27
  .rte-anchor-dialog input:focus {
28
28
  outline: none !important;
29
29
  }
30
- `,document.head.appendChild(i)}let p="";const x=document.createElement("div");x.style.cssText=`
30
+ `,document.head.appendChild(s)}let l="";const h=document.createElement("div");h.style.cssText=`
31
31
  display: flex;
32
32
  align-items: center;
33
33
  justify-content: space-between;
34
34
  padding: 16px 20px;
35
35
  border-bottom: 1px solid ${e.border};
36
36
  background: ${e.panelBg};
37
- `;const C=document.createElement("h3");C.style.cssText=`margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`,C.textContent="Add Anchor";const c=document.createElement("button");c.textContent="✕",c.style.cssText=`
37
+ `;const C=document.createElement("h3");C.style.cssText=`margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`,C.textContent="Add Anchor";const f=document.createElement("button");f.textContent="✕",f.style.cssText=`
38
38
  background: none;
39
39
  border: none;
40
40
  font-size: 24px;
@@ -48,7 +48,7 @@
48
48
  justify-content: center;
49
49
  border-radius: 4px;
50
50
  transition: all 0.2s ease;
51
- `,c.onmouseover=()=>{c.style.background=e.closeHoverBg,c.style.color="#f8fafc"},c.onmouseout=()=>{c.style.background="none",c.style.color=e.muted},x.appendChild(C),x.appendChild(c);const B=document.createElement("div");B.style.cssText="padding: 20px;";const b=document.createElement("div");b.style.cssText="margin-bottom: 0;";const y=document.createElement("label");y.textContent="Anchor ID",y.style.cssText=`display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`,y.setAttribute("for","anchor-id-input");const t=document.createElement("input");t.id="anchor-id-input",t.type="text",t.placeholder="e.g., section-introduction",t.value="",t.style.cssText=`
51
+ `,f.onmouseover=()=>{f.style.background=e.closeHoverBg,f.style.color="#f8fafc"},f.onmouseout=()=>{f.style.background="none",f.style.color=e.muted},h.appendChild(C),h.appendChild(f);const B=document.createElement("div");B.style.cssText="padding: 20px;";const m=document.createElement("div");m.style.cssText="margin-bottom: 0;";const y=document.createElement("label");y.textContent="Anchor ID",y.style.cssText=`display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`,y.setAttribute("for","anchor-id-input");const o=document.createElement("input");o.id="anchor-id-input",o.type="text",o.placeholder="e.g., section-introduction",o.value="",o.style.cssText=`
52
52
  width: 100%;
53
53
  padding: 10px 12px;
54
54
  font-size: 14px;
@@ -59,12 +59,12 @@
59
59
  background: ${e.fieldBg};
60
60
  transition: all 0.2s ease;
61
61
  box-sizing: border-box;
62
- `,t.style.setProperty("caret-color",e.fieldText);const f=document.createElement("div");f.style.cssText=`
62
+ `,o.style.setProperty("caret-color",e.fieldText);const p=document.createElement("div");p.style.cssText=`
63
63
  color: #d32f2f;
64
64
  font-size: 12px;
65
65
  margin-top: 6px;
66
66
  display: none;
67
- `;const k=document.createElement("div");k.textContent="URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.",k.style.cssText=`color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,b.appendChild(y),b.appendChild(t),b.appendChild(f),b.appendChild(k),B.appendChild(b);const v=document.createElement("div");v.style.cssText=`
67
+ `;const k=document.createElement("div");k.textContent="URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.",k.style.cssText=`color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`,m.appendChild(y),m.appendChild(o),m.appendChild(p),m.appendChild(k),B.appendChild(m);const v=document.createElement("div");v.style.cssText=`
68
68
  display: flex;
69
69
  gap: 12px;
70
70
  padding: 16px 20px;
@@ -81,7 +81,7 @@
81
81
  transition: all 0.2s ease;
82
82
  background: ${e.cancelBg};
83
83
  color: ${e.cancelText};
84
- `,g.onmouseover=()=>g.style.background=e.cancelHover,g.onmouseout=()=>g.style.background=e.cancelBg;const n=document.createElement("button");n.textContent="Add Anchor",n.style.cssText=`
84
+ `,g.onmouseover=()=>g.style.background=e.cancelHover,g.onmouseout=()=>g.style.background=e.cancelBg;const a=document.createElement("button");a.textContent="Add Anchor",a.style.cssText=`
85
85
  padding: 8px 16px;
86
86
  font-size: 14px;
87
87
  font-weight: 500;
@@ -91,11 +91,11 @@
91
91
  transition: all 0.2s ease;
92
92
  background: ${e.saveBg};
93
93
  color: white;
94
- `,n.disabled=!t.value.trim();const $=()=>{t.value.trim()?(n.disabled=!1,n.style.background=e.saveBg,n.style.color="white",n.style.cursor="pointer"):(n.disabled=!0,n.style.background=e.saveDisabledBg,n.style.color=e.saveDisabledText,n.style.cursor="not-allowed")};n.onmouseover=()=>{n.disabled||(n.style.background=e.saveHover,n.style.boxShadow=l?"0 2px 8px rgba(59, 130, 246, 0.35)":"0 2px 8px rgba(0, 102, 204, 0.3)")},n.onmouseout=()=>{n.disabled||(n.style.background=e.saveBg,n.style.boxShadow="none")},v.appendChild(g),v.appendChild(n),t.oninput=()=>{const i=t.value;if($(),i.trim()){const T=S(i);T.valid?h.has(i)?(p=`Anchor ID already exists: ${i}`,f.textContent="⚠ "+p,f.style.display="block",t.style.borderColor=e.fieldErrorBorder,t.style.background=e.fieldErrorBg):(p="",f.style.display="none",t.style.borderColor=e.fieldBorder,t.style.background=e.fieldBg):(p=T.error,f.textContent="⚠ "+p,f.style.display="block",t.style.borderColor=e.fieldErrorBorder,t.style.background=e.fieldErrorBg)}else f.style.display="none",t.style.borderColor=e.fieldBorder,t.style.background=e.fieldBg},t.onfocus=()=>{t.style.borderColor=p?e.fieldErrorBorder:e.saveBg,t.style.boxShadow=p?`0 0 0 3px ${e.errorRing}`:`0 0 0 3px ${e.focusRing}`,t.style.background=p?e.fieldErrorBg:e.fieldFocusBg},t.onblur=()=>{t.style.boxShadow="none",p||(t.style.background=e.fieldBg)};const A=()=>{const i=t.value.trim();!i||!S(i).valid||h.has(i)||(s&&s(i),a.remove())},E=()=>{a.remove()};n.onclick=A,g.onclick=E,c.onclick=E,t.onkeydown=i=>{i.key==="Enter"?(i.preventDefault(),A()):i.key==="Escape"&&(i.preventDefault(),E())},a.onclick=i=>{i.target===a&&E()},u.appendChild(x),u.appendChild(B),u.appendChild(v),a.appendChild(u),document.body.appendChild(a),setTimeout(()=>t.focus(),100)}function _(o,d){let s;if(d)s=d;else{const a=window.getSelection();if(!a||a.rangeCount===0)return;s=a.getRangeAt(0)}const r=document.createElement("span");r.id=o,r.className="rte-anchor",r.setAttribute("data-type","anchor"),r.setAttribute("data-anchor-id",o),r.setAttribute("title",`Anchor: ${o}`),r.style.cssText=`
94
+ `,a.disabled=!o.value.trim();const N=()=>{o.value.trim()?(a.disabled=!1,a.style.background=e.saveBg,a.style.color="white",a.style.cursor="pointer"):(a.disabled=!0,a.style.background=e.saveDisabledBg,a.style.color=e.saveDisabledText,a.style.cursor="not-allowed")};a.onmouseover=()=>{a.disabled||(a.style.background=e.saveHover,a.style.boxShadow=d?"0 2px 8px rgba(59, 130, 246, 0.35)":"0 2px 8px rgba(0, 102, 204, 0.3)")},a.onmouseout=()=>{a.disabled||(a.style.background=e.saveBg,a.style.boxShadow="none")},v.appendChild(g),v.appendChild(a),o.oninput=()=>{const s=o.value;if(N(),s.trim()){const T=S(s);T.valid?b.has(s)?(l=`Anchor ID already exists: ${s}`,p.textContent="⚠ "+l,p.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg):(l="",p.style.display="none",o.style.borderColor=e.fieldBorder,o.style.background=e.fieldBg):(l=T.error,p.textContent="⚠ "+l,p.style.display="block",o.style.borderColor=e.fieldErrorBorder,o.style.background=e.fieldErrorBg)}else p.style.display="none",o.style.borderColor=e.fieldBorder,o.style.background=e.fieldBg},o.onfocus=()=>{o.style.borderColor=l?e.fieldErrorBorder:e.saveBg,o.style.boxShadow=l?`0 0 0 3px ${e.errorRing}`:`0 0 0 3px ${e.focusRing}`,o.style.background=l?e.fieldErrorBg:e.fieldFocusBg},o.onblur=()=>{o.style.boxShadow="none",l||(o.style.background=e.fieldBg)};const A=()=>{const s=o.value.trim();!s||!S(s).valid||b.has(s)||(i&&i(s),n.remove())},E=()=>{n.remove()};a.onclick=A,g.onclick=E,f.onclick=E,o.onkeydown=s=>{s.key==="Enter"?(s.preventDefault(),A()):s.key==="Escape"&&(s.preventDefault(),E())},n.onclick=s=>{s.target===n&&E()},u.appendChild(h),u.appendChild(B),u.appendChild(v),n.appendChild(u),document.body.appendChild(n),setTimeout(()=>o.focus(),100)}function _(t,c){let i;if(c)i=c;else{const l=window.getSelection();if(!l||l.rangeCount===0)return;i=l.getRangeAt(0)}let r=null,d=i.startContainer;for(;d&&d!==document.body;){if(d.nodeType===Node.ELEMENT_NODE){const l=d;if(l.getAttribute("contenteditable")==="true"){r=l;break}}d=d.parentNode}const e=r?.innerHTML??"",n=document.createElement("span");n.id=t,n.className="rte-anchor",n.setAttribute("data-type","anchor"),n.setAttribute("data-anchor-id",t),n.setAttribute("title",`Anchor: ${t}`),n.style.cssText=`
95
95
  display: inline;
96
96
  position: relative;
97
97
  cursor: pointer;
98
- `,s.insertNode(r),h.add(o),s.setStart(r.nextSibling||r.parentNode,0),s.collapse(!0);const l=window.getSelection();l&&(l.removeAllRanges(),l.addRange(s));const e=w.findEditorContainerFromSelection();if(e){const a=w.getContentElement(e);a&&a.dispatchEvent(new Event("input",{bubbles:!0}))}D()}function D(){if(document.getElementById("rte-anchor-styles"))return;const o=document.createElement("style");o.id="rte-anchor-styles",o.textContent=`
98
+ `,i.insertNode(n),b.add(t),i.setStart(n.nextSibling||n.parentNode,0),i.collapse(!0);const u=window.getSelection();if(u&&(u.removeAllRanges(),u.addRange(i)),r)$(r,e),r.dispatchEvent(new Event("input",{bubbles:!0}));else{const l=w.findEditorContainerFromSelection();if(l){const h=w.getContentElement(l);h&&h.dispatchEvent(new Event("input",{bubbles:!0}))}}D()}function D(){if(document.getElementById("rte-anchor-styles"))return;const t=document.createElement("style");t.id="rte-anchor-styles",t.textContent=`
99
99
  .rte-anchor {
100
100
  display: inline;
101
101
  position: relative;
@@ -173,4 +173,4 @@
173
173
  outline: 2px solid #0066cc;
174
174
  outline-offset: 2px;
175
175
  }
176
- `,document.head.appendChild(o)}const H=()=>(typeof window<"u"&&(z(),D()),{name:"anchor",toolbar:[{label:"Anchor",command:"insertAnchor",icon:'<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M12 8.4C13.4912 8.4 14.7 7.19117 14.7 5.7C14.7 4.20883 13.4912 3 12 3C10.5088 3 9.3 4.20883 9.3 5.7C9.3 7.19117 10.5088 8.4 12 8.4ZM12 8.4V20.9999M12 20.9999C9.61305 20.9999 7.32387 20.0518 5.63604 18.364C3.94821 16.6761 3 14.3869 3 12H5M12 20.9999C14.3869 20.9999 16.6761 20.0518 18.364 18.364C20.0518 16.6761 21 14.3869 21 12H19" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-k"}],commands:{insertAnchor:()=>{try{const o=window.getSelection();if(!o||o.rangeCount===0)return alert("Please place your cursor where you want to insert the anchor."),!1;const d=o.getRangeAt(0).cloneRange();return M("add","",s=>{_(s,d)},d),!0}catch(o){return console.error("Failed to insert anchor:",o),!1}}},keymap:{"Mod-Shift-k":"insertAnchor"}});exports.AnchorPlugin=H;
176
+ `,document.head.appendChild(t)}const I=()=>(typeof window<"u"&&(z(),D()),{name:"anchor",toolbar:[{label:"Anchor",command:"insertAnchor",icon:'<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M12 8.4C13.4912 8.4 14.7 7.19117 14.7 5.7C14.7 4.20883 13.4912 3 12 3C10.5088 3 9.3 4.20883 9.3 5.7C9.3 7.19117 10.5088 8.4 12 8.4ZM12 8.4V20.9999M12 20.9999C9.61305 20.9999 7.32387 20.0518 5.63604 18.364C3.94821 16.6761 3 14.3869 3 12H5M12 20.9999C14.3869 20.9999 16.6761 20.0518 18.364 18.364C20.0518 16.6761 21 14.3869 21 12H19" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',shortcut:"Mod-Shift-k"}],commands:{insertAnchor:()=>{try{const t=window.getSelection();if(!t||t.rangeCount===0)return alert("Please place your cursor where you want to insert the anchor."),!1;const c=t.getRangeAt(0).cloneRange();return H("add","",i=>{_(i,c)},c),!0}catch(t){return console.error("Failed to insert anchor:",t),!1}}},keymap:{"Mod-Shift-k":"insertAnchor"}});exports.AnchorPlugin=I;
@@ -1,19 +1,28 @@
1
- import { f as S, g as D } from "./editorContainerHelpers-C7kdWnS0.mjs";
2
- const h = /* @__PURE__ */ new Set(), m = '[data-theme="dark"], .dark, .editora-theme-dark';
1
+ import { f as D, g as S } from "./editorContainerHelpers-C7kdWnS0.mjs";
2
+ const b = /* @__PURE__ */ new Set(), x = '[data-theme="dark"], .dark, .editora-theme-dark';
3
+ function z(t, c) {
4
+ if (c === t.innerHTML) return;
5
+ const i = window.execEditorCommand || window.executeEditorCommand;
6
+ if (typeof i == "function")
7
+ try {
8
+ i("recordDomTransaction", t, c, t.innerHTML);
9
+ } catch {
10
+ }
11
+ }
3
12
  function R() {
4
13
  if (typeof window > "u" || window.__anchorObserverInitialized) return;
5
- window.__anchorObserverInitialized = !0, new MutationObserver((l) => {
6
- l.forEach((i) => {
7
- i.removedNodes.forEach((r) => {
8
- if (r.nodeType === Node.ELEMENT_NODE) {
9
- const d = r;
14
+ window.__anchorObserverInitialized = !0, new MutationObserver((c) => {
15
+ c.forEach((i) => {
16
+ i.removedNodes.forEach((n) => {
17
+ if (n.nodeType === Node.ELEMENT_NODE) {
18
+ const d = n;
10
19
  if (d.classList?.contains("rte-anchor")) {
11
- const a = d.id;
12
- a && h.delete(a);
20
+ const r = d.id;
21
+ r && b.delete(r);
13
22
  }
14
- d.querySelectorAll?.(".rte-anchor")?.forEach((a) => {
15
- const u = a.id;
16
- u && h.delete(u);
23
+ d.querySelectorAll?.(".rte-anchor")?.forEach((r) => {
24
+ const u = r.id;
25
+ u && b.delete(u);
17
26
  });
18
27
  }
19
28
  });
@@ -23,35 +32,35 @@ function R() {
23
32
  subtree: !0
24
33
  });
25
34
  }
26
- function A(o) {
27
- return !o || o.trim().length === 0 ? { valid: !1, error: "Anchor ID cannot be empty" } : o.length > 256 ? { valid: !1, error: "Anchor ID must be less than 256 characters" } : /^[a-z_]/.test(o) ? /^[a-z0-9\-_]+$/.test(o) ? { valid: !0, error: "" } : { valid: !1, error: "Anchor ID can only contain letters, numbers, hyphens, and underscores" } : { valid: !1, error: "Anchor ID must start with a letter or underscore" };
35
+ function A(t) {
36
+ return !t || t.trim().length === 0 ? { valid: !1, error: "Anchor ID cannot be empty" } : t.length > 256 ? { valid: !1, error: "Anchor ID must be less than 256 characters" } : /^[a-z_]/.test(t) ? /^[a-z0-9\-_]+$/.test(t) ? { valid: !0, error: "" } : { valid: !1, error: "Anchor ID can only contain letters, numbers, hyphens, and underscores" } : { valid: !1, error: "Anchor ID must start with a letter or underscore" };
28
37
  }
29
- function N() {
30
- const o = S();
31
- if (!o) return;
32
- const l = D(o);
33
- if (!l) return;
34
- const i = l.querySelectorAll(".rte-anchor"), r = /* @__PURE__ */ new Set();
38
+ function M() {
39
+ const t = D();
40
+ if (!t) return;
41
+ const c = S(t);
42
+ if (!c) return;
43
+ const i = c.querySelectorAll(".rte-anchor"), n = /* @__PURE__ */ new Set();
35
44
  i.forEach((d) => {
36
45
  const e = d.id;
37
- e && r.add(e);
38
- }), h.clear(), r.forEach((d) => h.add(d));
46
+ e && n.add(e);
47
+ }), b.clear(), n.forEach((d) => b.add(d));
39
48
  }
40
- function M(o) {
41
- if (o) {
42
- const r = o.startContainer;
43
- if ((r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement)?.closest(m)) return !0;
49
+ function H(t) {
50
+ if (t) {
51
+ const n = t.startContainer;
52
+ if ((n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(x)) return !0;
44
53
  }
45
- const l = window.getSelection();
46
- if (l && l.rangeCount > 0) {
47
- const r = l.getRangeAt(0).startContainer;
48
- if ((r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement)?.closest(m)) return !0;
54
+ const c = window.getSelection();
55
+ if (c && c.rangeCount > 0) {
56
+ const n = c.getRangeAt(0).startContainer;
57
+ if ((n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(x)) return !0;
49
58
  }
50
- return document.activeElement?.closest(m) ? !0 : document.body.matches(m) || document.documentElement.matches(m);
59
+ return document.activeElement?.closest(x) ? !0 : document.body.matches(x) || document.documentElement.matches(x);
51
60
  }
52
- function _(o, l, i, r) {
53
- N();
54
- const d = M(r), e = d ? {
61
+ function _(t, c, i, n) {
62
+ M();
63
+ const d = H(n), e = d ? {
55
64
  overlay: "rgba(0, 0, 0, 0.62)",
56
65
  dialogBg: "#1f2937",
57
66
  panelBg: "#222d3a",
@@ -99,8 +108,8 @@ function _(o, l, i, r) {
99
108
  help: "#999999",
100
109
  focusRing: "rgba(0, 102, 204, 0.1)",
101
110
  errorRing: "rgba(211, 47, 47, 0.1)"
102
- }, a = document.createElement("div");
103
- a.className = "rte-anchor-dialog-overlay", a.style.cssText = `
111
+ }, r = document.createElement("div");
112
+ r.className = "rte-anchor-dialog-overlay", r.style.cssText = `
104
113
  position: fixed;
105
114
  top: 0;
106
115
  left: 0;
@@ -135,9 +144,9 @@ function _(o, l, i, r) {
135
144
  }
136
145
  `, document.head.appendChild(s);
137
146
  }
138
- let p = "";
139
- const x = document.createElement("div");
140
- x.style.cssText = `
147
+ let l = "";
148
+ const h = document.createElement("div");
149
+ h.style.cssText = `
141
150
  display: flex;
142
151
  align-items: center;
143
152
  justify-content: space-between;
@@ -147,8 +156,8 @@ function _(o, l, i, r) {
147
156
  `;
148
157
  const w = document.createElement("h3");
149
158
  w.style.cssText = `margin: 0; font-size: 18px; font-weight: 600; color: ${e.text};`, w.textContent = "Add Anchor";
150
- const c = document.createElement("button");
151
- c.textContent = "✕", c.style.cssText = `
159
+ const f = document.createElement("button");
160
+ f.textContent = "✕", f.style.cssText = `
152
161
  background: none;
153
162
  border: none;
154
163
  font-size: 24px;
@@ -162,19 +171,19 @@ function _(o, l, i, r) {
162
171
  justify-content: center;
163
172
  border-radius: 4px;
164
173
  transition: all 0.2s ease;
165
- `, c.onmouseover = () => {
166
- c.style.background = e.closeHoverBg, c.style.color = "#f8fafc";
167
- }, c.onmouseout = () => {
168
- c.style.background = "none", c.style.color = e.muted;
169
- }, x.appendChild(w), x.appendChild(c);
174
+ `, f.onmouseover = () => {
175
+ f.style.background = e.closeHoverBg, f.style.color = "#f8fafc";
176
+ }, f.onmouseout = () => {
177
+ f.style.background = "none", f.style.color = e.muted;
178
+ }, h.appendChild(w), h.appendChild(f);
170
179
  const C = document.createElement("div");
171
180
  C.style.cssText = "padding: 20px;";
172
- const b = document.createElement("div");
173
- b.style.cssText = "margin-bottom: 0;";
181
+ const m = document.createElement("div");
182
+ m.style.cssText = "margin-bottom: 0;";
174
183
  const y = document.createElement("label");
175
184
  y.textContent = "Anchor ID", y.style.cssText = `display: block; font-size: 14px; font-weight: 500; color: ${e.text}; margin-bottom: 8px;`, y.setAttribute("for", "anchor-id-input");
176
- const t = document.createElement("input");
177
- t.id = "anchor-id-input", t.type = "text", t.placeholder = "e.g., section-introduction", t.value = "", t.style.cssText = `
185
+ const o = document.createElement("input");
186
+ o.id = "anchor-id-input", o.type = "text", o.placeholder = "e.g., section-introduction", o.value = "", o.style.cssText = `
178
187
  width: 100%;
179
188
  padding: 10px 12px;
180
189
  font-size: 14px;
@@ -185,16 +194,16 @@ function _(o, l, i, r) {
185
194
  background: ${e.fieldBg};
186
195
  transition: all 0.2s ease;
187
196
  box-sizing: border-box;
188
- `, t.style.setProperty("caret-color", e.fieldText);
189
- const f = document.createElement("div");
190
- f.style.cssText = `
197
+ `, o.style.setProperty("caret-color", e.fieldText);
198
+ const p = document.createElement("div");
199
+ p.style.cssText = `
191
200
  color: #d32f2f;
192
201
  font-size: 12px;
193
202
  margin-top: 6px;
194
203
  display: none;
195
204
  `;
196
205
  const B = document.createElement("div");
197
- B.textContent = "URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.", B.style.cssText = `color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`, b.appendChild(y), b.appendChild(t), b.appendChild(f), b.appendChild(B), C.appendChild(b);
206
+ B.textContent = "URL-safe ID (letters, numbers, hyphens, underscores). Must start with letter or underscore.", B.style.cssText = `color: ${e.help}; font-size: 12px; margin-top: 8px; line-height: 1.4;`, m.appendChild(y), m.appendChild(o), m.appendChild(p), m.appendChild(B), C.appendChild(m);
198
207
  const v = document.createElement("div");
199
208
  v.style.cssText = `
200
209
  display: flex;
@@ -216,8 +225,8 @@ function _(o, l, i, r) {
216
225
  background: ${e.cancelBg};
217
226
  color: ${e.cancelText};
218
227
  `, g.onmouseover = () => g.style.background = e.cancelHover, g.onmouseout = () => g.style.background = e.cancelBg;
219
- const n = document.createElement("button");
220
- n.textContent = "Add Anchor", n.style.cssText = `
228
+ const a = document.createElement("button");
229
+ a.textContent = "Add Anchor", a.style.cssText = `
221
230
  padding: 8px 16px;
222
231
  font-size: 14px;
223
232
  font-weight: 500;
@@ -227,66 +236,80 @@ function _(o, l, i, r) {
227
236
  transition: all 0.2s ease;
228
237
  background: ${e.saveBg};
229
238
  color: white;
230
- `, n.disabled = !t.value.trim();
231
- const z = () => {
232
- t.value.trim() ? (n.disabled = !1, n.style.background = e.saveBg, n.style.color = "white", n.style.cursor = "pointer") : (n.disabled = !0, n.style.background = e.saveDisabledBg, n.style.color = e.saveDisabledText, n.style.cursor = "not-allowed");
239
+ `, a.disabled = !o.value.trim();
240
+ const $ = () => {
241
+ o.value.trim() ? (a.disabled = !1, a.style.background = e.saveBg, a.style.color = "white", a.style.cursor = "pointer") : (a.disabled = !0, a.style.background = e.saveDisabledBg, a.style.color = e.saveDisabledText, a.style.cursor = "not-allowed");
233
242
  };
234
- n.onmouseover = () => {
235
- n.disabled || (n.style.background = e.saveHover, n.style.boxShadow = d ? "0 2px 8px rgba(59, 130, 246, 0.35)" : "0 2px 8px rgba(0, 102, 204, 0.3)");
236
- }, n.onmouseout = () => {
237
- n.disabled || (n.style.background = e.saveBg, n.style.boxShadow = "none");
238
- }, v.appendChild(g), v.appendChild(n), t.oninput = () => {
239
- const s = t.value;
240
- if (z(), s.trim()) {
243
+ a.onmouseover = () => {
244
+ a.disabled || (a.style.background = e.saveHover, a.style.boxShadow = d ? "0 2px 8px rgba(59, 130, 246, 0.35)" : "0 2px 8px rgba(0, 102, 204, 0.3)");
245
+ }, a.onmouseout = () => {
246
+ a.disabled || (a.style.background = e.saveBg, a.style.boxShadow = "none");
247
+ }, v.appendChild(g), v.appendChild(a), o.oninput = () => {
248
+ const s = o.value;
249
+ if ($(), s.trim()) {
241
250
  const k = A(s);
242
- k.valid ? h.has(s) ? (p = `Anchor ID already exists: ${s}`, f.textContent = "⚠ " + p, f.style.display = "block", t.style.borderColor = e.fieldErrorBorder, t.style.background = e.fieldErrorBg) : (p = "", f.style.display = "none", t.style.borderColor = e.fieldBorder, t.style.background = e.fieldBg) : (p = k.error, f.textContent = "⚠ " + p, f.style.display = "block", t.style.borderColor = e.fieldErrorBorder, t.style.background = e.fieldErrorBg);
251
+ k.valid ? b.has(s) ? (l = `Anchor ID already exists: ${s}`, p.textContent = "⚠ " + l, p.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg) : (l = "", p.style.display = "none", o.style.borderColor = e.fieldBorder, o.style.background = e.fieldBg) : (l = k.error, p.textContent = "⚠ " + l, p.style.display = "block", o.style.borderColor = e.fieldErrorBorder, o.style.background = e.fieldErrorBg);
243
252
  } else
244
- f.style.display = "none", t.style.borderColor = e.fieldBorder, t.style.background = e.fieldBg;
245
- }, t.onfocus = () => {
246
- t.style.borderColor = p ? e.fieldErrorBorder : e.saveBg, t.style.boxShadow = p ? `0 0 0 3px ${e.errorRing}` : `0 0 0 3px ${e.focusRing}`, t.style.background = p ? e.fieldErrorBg : e.fieldFocusBg;
247
- }, t.onblur = () => {
248
- t.style.boxShadow = "none", p || (t.style.background = e.fieldBg);
253
+ p.style.display = "none", o.style.borderColor = e.fieldBorder, o.style.background = e.fieldBg;
254
+ }, o.onfocus = () => {
255
+ o.style.borderColor = l ? e.fieldErrorBorder : e.saveBg, o.style.boxShadow = l ? `0 0 0 3px ${e.errorRing}` : `0 0 0 3px ${e.focusRing}`, o.style.background = l ? e.fieldErrorBg : e.fieldFocusBg;
256
+ }, o.onblur = () => {
257
+ o.style.boxShadow = "none", l || (o.style.background = e.fieldBg);
249
258
  };
250
259
  const T = () => {
251
- const s = t.value.trim();
252
- !s || !A(s).valid || h.has(s) || (i && i(s), a.remove());
260
+ const s = o.value.trim();
261
+ !s || !A(s).valid || b.has(s) || (i && i(s), r.remove());
253
262
  }, E = () => {
254
- a.remove();
263
+ r.remove();
255
264
  };
256
- n.onclick = T, g.onclick = E, c.onclick = E, t.onkeydown = (s) => {
265
+ a.onclick = T, g.onclick = E, f.onclick = E, o.onkeydown = (s) => {
257
266
  s.key === "Enter" ? (s.preventDefault(), T()) : s.key === "Escape" && (s.preventDefault(), E());
258
- }, a.onclick = (s) => {
259
- s.target === a && E();
260
- }, u.appendChild(x), u.appendChild(C), u.appendChild(v), a.appendChild(u), document.body.appendChild(a), setTimeout(() => t.focus(), 100);
267
+ }, r.onclick = (s) => {
268
+ s.target === r && E();
269
+ }, u.appendChild(h), u.appendChild(C), u.appendChild(v), r.appendChild(u), document.body.appendChild(r), setTimeout(() => o.focus(), 100);
261
270
  }
262
- function H(o, l) {
271
+ function I(t, c) {
263
272
  let i;
264
- if (l)
265
- i = l;
273
+ if (c)
274
+ i = c;
266
275
  else {
267
- const a = window.getSelection();
268
- if (!a || a.rangeCount === 0) return;
269
- i = a.getRangeAt(0);
276
+ const l = window.getSelection();
277
+ if (!l || l.rangeCount === 0) return;
278
+ i = l.getRangeAt(0);
270
279
  }
271
- const r = document.createElement("span");
272
- r.id = o, r.className = "rte-anchor", r.setAttribute("data-type", "anchor"), r.setAttribute("data-anchor-id", o), r.setAttribute("title", `Anchor: ${o}`), r.style.cssText = `
280
+ let n = null, d = i.startContainer;
281
+ for (; d && d !== document.body; ) {
282
+ if (d.nodeType === Node.ELEMENT_NODE) {
283
+ const l = d;
284
+ if (l.getAttribute("contenteditable") === "true") {
285
+ n = l;
286
+ break;
287
+ }
288
+ }
289
+ d = d.parentNode;
290
+ }
291
+ const e = n?.innerHTML ?? "", r = document.createElement("span");
292
+ r.id = t, r.className = "rte-anchor", r.setAttribute("data-type", "anchor"), r.setAttribute("data-anchor-id", t), r.setAttribute("title", `Anchor: ${t}`), r.style.cssText = `
273
293
  display: inline;
274
294
  position: relative;
275
295
  cursor: pointer;
276
- `, i.insertNode(r), h.add(o), i.setStart(r.nextSibling || r.parentNode, 0), i.collapse(!0);
277
- const d = window.getSelection();
278
- d && (d.removeAllRanges(), d.addRange(i));
279
- const e = S();
280
- if (e) {
281
- const a = D(e);
282
- a && a.dispatchEvent(new Event("input", { bubbles: !0 }));
296
+ `, i.insertNode(r), b.add(t), i.setStart(r.nextSibling || r.parentNode, 0), i.collapse(!0);
297
+ const u = window.getSelection();
298
+ if (u && (u.removeAllRanges(), u.addRange(i)), n)
299
+ z(n, e), n.dispatchEvent(new Event("input", { bubbles: !0 }));
300
+ else {
301
+ const l = D();
302
+ if (l) {
303
+ const h = S(l);
304
+ h && h.dispatchEvent(new Event("input", { bubbles: !0 }));
305
+ }
283
306
  }
284
- $();
307
+ N();
285
308
  }
286
- function $() {
309
+ function N() {
287
310
  if (document.getElementById("rte-anchor-styles")) return;
288
- const o = document.createElement("style");
289
- o.id = "rte-anchor-styles", o.textContent = `
311
+ const t = document.createElement("style");
312
+ t.id = "rte-anchor-styles", t.textContent = `
290
313
  .rte-anchor {
291
314
  display: inline;
292
315
  position: relative;
@@ -364,9 +387,9 @@ function $() {
364
387
  outline: 2px solid #0066cc;
365
388
  outline-offset: 2px;
366
389
  }
367
- `, document.head.appendChild(o);
390
+ `, document.head.appendChild(t);
368
391
  }
369
- const O = () => (typeof window < "u" && (R(), $()), {
392
+ const O = () => (typeof window < "u" && (R(), N()), {
370
393
  name: "anchor",
371
394
  toolbar: [
372
395
  {
@@ -379,15 +402,15 @@ const O = () => (typeof window < "u" && (R(), $()), {
379
402
  commands: {
380
403
  insertAnchor: () => {
381
404
  try {
382
- const o = window.getSelection();
383
- if (!o || o.rangeCount === 0)
405
+ const t = window.getSelection();
406
+ if (!t || t.rangeCount === 0)
384
407
  return alert("Please place your cursor where you want to insert the anchor."), !1;
385
- const l = o.getRangeAt(0).cloneRange();
408
+ const c = t.getRangeAt(0).cloneRange();
386
409
  return _("add", "", (i) => {
387
- H(i, l);
388
- }, l), !0;
389
- } catch (o) {
390
- return console.error("Failed to insert anchor:", o), !1;
410
+ I(i, c);
411
+ }, c), !0;
412
+ } catch (t) {
413
+ return console.error("Failed to insert anchor:", t), !1;
391
414
  }
392
415
  }
393
416
  },
@@ -0,0 +1 @@
1
+ "use strict";const b="p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";function p(e){return!!e.cloneContents().querySelector(b)}function v(e,t){return(e?.nodeType===Node.ELEMENT_NODE?e:e?.parentElement??null)?.closest('[contenteditable="true"]')||t()?.querySelector('[contenteditable="true"]')||document.querySelector('[contenteditable="true"]')}function C(e,t){const n=v(e,t);n&&n.dispatchEvent(new Event("input",{bubbles:!0}))}function A(e,t){let r=e.startContainer.nodeType===Node.TEXT_NODE?e.startContainer.parentElement:e.startContainer;for(;r&&r!==document.body;){if(r.classList.contains(t)){const c=document.createRange();if(c.selectNodeContents(r),c.compareBoundaryPoints(Range.START_TO_START,e)<=0&&c.compareBoundaryPoints(Range.END_TO_END,e)>=0)return r}r=r.parentElement}return null}function S(e){try{if(e.savedRange){const o=window.getSelection();o&&(o.removeAllRanges(),o.addRange(e.savedRange.cloneRange()))}const t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return!1;const n=t.getRangeAt(0);if(n.collapsed)return!1;const r=A(n,e.className);if(r)return e.styleProperty==="backgroundColor"?r.style.backgroundColor=e.color:r.style.color=e.color,C(r,e.getActiveEditorRoot),!0;v(n.commonAncestorContainer,e.getActiveEditorRoot)?.focus({preventScroll:!0});try{document.execCommand("styleWithCSS",!1,"true")}catch{}let l=!1;if(e.commands.forEach(o=>{l||(l=document.execCommand(o,!1,e.color))}),!l&&!p(n)){const o=document.createElement("span");e.styleProperty==="backgroundColor"?o.style.backgroundColor=e.color:o.style.color=e.color,o.className=e.className;const a=n.extractContents();o.appendChild(a),n.insertNode(o),n.setStartAfter(o),n.collapse(!0),t.removeAllRanges(),t.addRange(n),l=!0}return l?(C(n.commonAncestorContainer,e.getActiveEditorRoot),!0):(e.warnMessage&&console.warn(e.warnMessage),!1)}catch(t){return e.warnMessage?console.error(e.warnMessage,t):console.error("[ColorApply] Failed to apply color",t),!1}}function T({popover:e,anchor:t,onClose:n,gap:r=6,margin:c=8,zIndex:l=1e4}){e.style.position="fixed",e.style.zIndex=`${l}`,e.style.visibility="hidden";const o=()=>{if(!e.isConnected||!t.isConnected){n();return}const s=t.getBoundingClientRect();if(s.width===0&&s.height===0){n();return}const i=e.getBoundingClientRect(),y=i.width||e.offsetWidth||220,f=i.height||e.offsetHeight||260,w=window.innerWidth,E=window.innerHeight;let u=s.left,d=s.bottom+r;if(u+y>w-c&&(u=w-y-c),u=Math.max(c,u),d+f>E-c){const g=s.top-f-r;g>=c?d=g:d=Math.max(c,E-f-c)}d<c&&(d=c),e.style.left=`${Math.round(u)}px`,e.style.top=`${Math.round(d)}px`,e.style.visibility="visible"},a=()=>{o()},m=s=>{const i=s.target;i&&(e.contains(i)||t.contains(i)||n())},h=s=>{s.key==="Escape"&&n()};window.addEventListener("resize",a),window.addEventListener("scroll",a,!0),document.addEventListener("keydown",h);const R=window.requestAnimationFrame(()=>{document.addEventListener("mousedown",m,!0)});return o(),{reposition:o,destroy:()=>{window.cancelAnimationFrame(R),window.removeEventListener("resize",a),window.removeEventListener("scroll",a,!0),document.removeEventListener("keydown",h),document.removeEventListener("mousedown",m,!0)}}}exports.applyColorToSelection=S;exports.attachAnchoredPopover=T;